<template>
  <el-container class="layout-container">
    <el-aside width="200px">

      <el-menu :default-active="$route.path" router background-color="#002033" text-color="#fff" active-text-color="#ffd04b">
        <el-menu-item index="/welcome">
          <i class="el-icon-s-home"></i>
          <span slot="title">首页</span>
        </el-menu-item>
        <el-menu-item index="/article">
          <i class=" iconfont  el-icon-document "></i>
          <span slot="title">内容管理</span>
        </el-menu-item>
        <el-menu-item index="/image">
          <i class=" iconfont  el-icon-picture"></i>
          <span slot="title">素材管理</span>
        </el-menu-item>
        <el-menu-item index="/publish">
          <i class="el-icon-s-promotion"></i>
          <span slot="title">发布文章</span>
        </el-menu-item>
        <el-menu-item index="/comment">
          <i class="el-icon-chat-dot-round"></i>
          <span slot="title">评论管理</span>
        </el-menu-item>
        <el-menu-item index="/fans">
          <i class="el-icon-present"></i>
          <span slot="title">粉丝管理</span>
        </el-menu-item>
        <el-menu-item index="/setting">
          <i class="el-icon-setting    "></i>
          <span slot="title">个人设置</span>
        </el-menu-item>
      </el-menu>
    </el-aside>
    <el-container>
      <el-header>
        <div>
          <i class="el-icon-s-fold   iconspan  "></i>
          <span>江苏传智播客科技教育有限公司</span>
        </div>
        <el-dropdown>
          <div>
            <img :src="user.photo">
            <span> {{user.name}}</span>
            <i class="el-icon-arrow-down el-icon--right"></i>
          </div>
          <el-dropdown-menu slot="dropdown">
            <el-dropdown-item @click.native='$router.push("/setting")'> <i class="el-icon-setting"></i> 个人设置</el-dropdown-item>
            <el-dropdown-item @click.native="loginOut"> <i class="el-icon-unlock"></i> 退出登陆</el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>
      </el-header>
      <el-main>
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>
<script>
import { getUserProfile } from '@/api/user.js'
import GlobalBus from '@/api/globalbus.js'
export default {
  data() {
    return {
      user: {}
    }
  },
  created() {
    this.getUserData()
    GlobalBus.$on('update-user', data => {
      this.user = data
    })
  },
  methods: {
    getUserData() {
      getUserProfile()
        .then(res => {
          this.user = res.data.data
        })
        .catch(() => {
          return this.$message.error('加载数据失败！')
        })
    },
    loginOut() {
      window.sessionStorage.removeItem('user')
      this.$router.push('/login')
    }
  }
}
</script>
<style scoped>
.layout-container {
  height: 100%;
}
.el-aside {
  /* height: 100%; */
  background-color: #d3dce6;
}
.el-header {
  background-color: #b3c0d1;
}
.el-menu {
  height: 100%;
}
.iconfont {
  margin-right: 5px;
  padding-left: 5px;
  width: 20px;
  font-size: 18px;
  vertical-align: middle;
}
.el-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 16px;
}
.el-header div {
  display: flex;
}
.el-header div span {
  font-size: 16px;
}
.iconspan {
  font-size: 24px;
  /* vertical-align: middle; */
}
.el-dropdown div {
  display: flex;
  align-items: center;
}
.el-dropdown img {
  width: 30px;
  height: 30px;
  vertical-align: middle;
  margin-right: 5px;
}
</style>
